package com.chh.util;

import java.io.*;

/**
 * @author 一碗情深
 * @since 2024-08-09 星期五 14:38:46
 */
public class FileUtils {

    /**
     * 写入序列化文件
     */
    public static void writeFileByte(byte[] b, String path) {
        File file = new File(path);
        try (FileOutputStream fos = new FileOutputStream(file)) {
            fos.write(b);
            fos.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 读取序列化文件
     */
    public static byte[] readFileByte(String path) {
        File file = new File(path);
        long size = file.length();
        byte[] b = new byte[(int) size];
        try (InputStream fis = new FileInputStream(file)) {
            if (fis.read(b) < 0) {
                return null;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return b;
    }

}
